-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Navigate prompt history in prompt field via arrow up/down (#4139) #4450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Navigate through prompt history using arrow up/down keys - Only triggers when cursor is at first line (up) or last line (down) - Preserves current input when starting navigation - Resets navigation state when typing or sending messages - Follows VSCode's standard UX patterns for history navigation
|
fixing issue where the history was inthe wrong order an it was also pulling from the pool of all history instead of just the workspace. |
- Remove reverse() to maintain chronological order in history array - Add workspace filtering to only show prompts from current workspace - Ensure arrow up navigates to older prompts (as expected) - Filter history items by workspace field matching current cwd
|
The test fail because windows is the problem :P |
|
Thanks, it looks good! const [inputValue, setInputValue] = useState<{
value: string;
afterRender?: "SET_CURSOR_FIRST_LINE" | "SET_CURSOR_LAST_LINE";
}>({
value: "",
});
useLayoutEffect(() => {
if (!inputValue.afterRender) return;
if (inputValue.afterRender === "SET_CURSOR_FIRST_LINE") {
if (textAreaRef.current) {
textAreaRef.current.setSelectionRange(0, 0);
}
} else if (inputValue.afterRender === "SET_CURSOR_LAST_LINE") {
if (textAreaRef.current) {
const lines = historicalPrompt.split("\n");
const lastLineStart =
historicalPrompt.length - lines[lines.length - 1].length;
textAreaRef.current.setSelectionRange(lastLineStart, lastLineStart);
}
}
setInputValue(({ value }) => ({ value }));
}, [inputValue]);
// Usage
setInputValue({
value: "...",
afterRender: "SET_CURSOR_FIRST_LINE",
});
setInputValue({
value: "...",
afterRender: "SET_CURSOR_LAST_LINE",
}); |
- Add missing taskHistory and cwd properties to all useExtensionState mocks - Add comprehensive test coverage for prompt history navigation feature - Ensure all 25 tests pass including new prompt history functionality Fixes failing Windows CI test in PR #4450
- Replace setTimeout(..., 0) with useLayoutEffect for more reliable cursor positioning - Implement state-based cursor positioning pattern suggested by @mochiya98 - Add CursorPositionState interface for better type safety - Maintain all existing functionality while improving timing reliability This addresses the technical suggestion in PR #4450 comment about using useLayoutEffect instead of setTimeout for DOM manipulation timing.
daniel-lxs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @hannesrudolph, I left some minor performance improvements suggestions.
…y management - Add useMemo for prompt history filtering to prevent unnecessary re-computations - Implement MAX_PROMPT_HISTORY_SIZE = 100 limit for memory management - Extract logic into usePromptHistory custom hook for better code organization - Simplify ChatTextArea component by delegating history logic to custom hook Addresses review feedback on PR #4450 for issue #4139
- Remove unused CursorPositionState interface from ChatTextArea - Remove unused destructured variables from usePromptHistory hook - Fix missing dependency in useEffect dependency array - Rename unused parameter with underscore prefix Related to #4139
- In chat: Use conversation messages (user_feedback), newest first - Out of chat: Use task history, oldest first - Reset navigation position when switching between history sources - Switch from taskHistory to clineMessages for active conversations - Maintain backward compatibility with task history fallback - Add comprehensive tests for hybrid behavior and position reset This provides intuitive UX where: - Users navigate recent conversation messages during tasks (newest first) - Users access initial task prompts when starting fresh (oldest first) - Navigation always starts fresh when switching contexts
Task history was using .slice(-100) which gets the newest 100 tasks, but we want to show oldest tasks first when navigating. Changed to .slice(0, 100) to get the oldest 100 tasks instead. This ensures that when starting fresh (no conversation), up arrow shows the oldest task prompts first, which is the intended behavior.
…order preservation
…ith imported types
daniel-lxs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested it and works quite well, pressing up outside a task brings up the newest task. Pressing up inside the task brings up the newest message sent by the user.
LGTM
|
It feels unintuitive to me that the up arrow within a task can also bring up messages from other tasks. Is that part of this necessary, or could we just restrict it to navigating through prompts in the current task? |
It should be restrcited to just the current task already |
Seems to be pulling up the |
…rsation When an active task has only an initial prompt with no follow-up user messages, the prompt history should return empty instead of falling back to task history. This fixes the "Starting Fresh" behavior appearing inappropriately. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit cc7bab0 solved the issue for me.
Looks good.
|
ok @mrubens try it now! |
|
there is a problem with the implementation when the prompt is multi line: it is no longer possible to navigate between lines in the current prompt with arrow up/down. as i wrote in my feature proposal, it should work as other native search fields in vscode that support multiple lines:
|
… (#4450) * feat: add prompt history navigation with arrow keys (#4139) - Navigate through prompt history using arrow up/down keys - Only triggers when cursor is at first line (up) or last line (down) - Preserves current input when starting navigation - Resets navigation state when typing or sending messages - Follows VSCode's standard UX patterns for history navigation * fix: correct prompt history order and add workspace filtering (#4139) - Remove reverse() to maintain chronological order in history array - Add workspace filtering to only show prompts from current workspace - Ensure arrow up navigates to older prompts (as expected) - Filter history items by workspace field matching current cwd * test: Fix Windows unit test failures for prompt history navigation - Add missing taskHistory and cwd properties to all useExtensionState mocks - Add comprehensive test coverage for prompt history navigation feature - Ensure all 25 tests pass including new prompt history functionality Fixes failing Windows CI test in PR #4450 * refactor: Improve cursor positioning with useLayoutEffect - Replace setTimeout(..., 0) with useLayoutEffect for more reliable cursor positioning - Implement state-based cursor positioning pattern suggested by @mochiya98 - Add CursorPositionState interface for better type safety - Maintain all existing functionality while improving timing reliability This addresses the technical suggestion in PR #4450 comment about using useLayoutEffect instead of setTimeout for DOM manipulation timing. * feat: optimize prompt history with performance improvements and memory management - Add useMemo for prompt history filtering to prevent unnecessary re-computations - Implement MAX_PROMPT_HISTORY_SIZE = 100 limit for memory management - Extract logic into usePromptHistory custom hook for better code organization - Simplify ChatTextArea component by delegating history logic to custom hook Addresses review feedback on PR #4450 for issue #4139 * refactor: clean up unused code and fix linting issues in prompt history - Remove unused CursorPositionState interface from ChatTextArea - Remove unused destructured variables from usePromptHistory hook - Fix missing dependency in useEffect dependency array - Rename unused parameter with underscore prefix Related to #4139 * feat: implement hybrid prompt history with position reset - In chat: Use conversation messages (user_feedback), newest first - Out of chat: Use task history, oldest first - Reset navigation position when switching between history sources - Switch from taskHistory to clineMessages for active conversations - Maintain backward compatibility with task history fallback - Add comprehensive tests for hybrid behavior and position reset This provides intuitive UX where: - Users navigate recent conversation messages during tasks (newest first) - Users access initial task prompts when starting fresh (oldest first) - Navigation always starts fresh when switching contexts * fix: correct task history slicing order for prompt navigation Task history was using .slice(-100) which gets the newest 100 tasks, but we want to show oldest tasks first when navigating. Changed to .slice(0, 100) to get the oldest 100 tasks instead. This ensures that when starting fresh (no conversation), up arrow shows the oldest task prompts first, which is the intended behavior. * refactor: remove comment on task history size limitation and clarify order preservation * refactor: replace local ClineMessage and TaskHistoryItem interfaces with imported types * fix: prevent prompt history fallback to task list during active conversation When an active task has only an initial prompt with no follow-up user messages, the prompt history should return empty instead of falling back to task history. This fixes the "Starting Fresh" behavior appearing inappropriately. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Daniel Riccio <[email protected]> Co-authored-by: Claude <[email protected]>

Fixes #4139
Description
This PR implements hybrid prompt history navigation using arrow up/down keys in the chat input field, providing an intuitive
terminal-like experience that adapts to the user's current context.
Key Features
Hybrid Navigation Sources
Smart Context Detection
clineMessagesandtaskHistoryas data sourcesTerminal-like UX
Performance & Memory Management
Navigation Behavior
In Active Conversation:
Starting Fresh (No Active Conversation):
Edge Cases:
Technical Implementation
usePromptHistoryhook encapsulates all navigation logic